package org.hank.wanandroid.adapter

import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import org.hank.wanandroid.R
import org.hank.wanandroid.bean.ArticleBean
import org.hank.wanandroid.constants.Constants
import org.hank.wanandroid.databinding.ItemviewHomeArticleBinding
import org.hank.wanandroid.databinding.ItemviewHomeProjectBinding

//  ┏┓　　　┏┓
//┏┛┻━━━┛┻┓
//┃　　　　　　　┃
//┃　　　━　　　┃
//┃　┳┛　┗┳　┃
//┃　　　　　　　┃
//┃　　　┻　　　┃
//┃　　　　　　　┃
//┗━┓　　　┏━┛
//    ┃　　　┃                  神兽保佑
//    ┃　　　┃                  永无BUG！
//    ┃　　　┗━━━┓
//    ┃　　　　　　　┣┓
//    ┃　　　　　　　┏┛
//    ┗┓┓┏━┳┓┏┛
//      ┃┫┫　┃┫┫
//      ┗┻┛　┗┻┛
/**
 *@auth: Hank
 *邮箱: cs16xiaoc1@163.com
 *创建时间: 2021/4/19 14:16
 *描述:
 */
class ArticleAdapter(data: MutableList<ArticleBean>) :
    BaseMultiItemQuickAdapter<ArticleBean, BaseDataBindingHolder<ViewDataBinding>>(data),
    LoadMoreModule {

    init {
        addItemType(Constants.ITEM_ARTICLE, R.layout.itemview_home_article)
        addItemType(Constants.ITEM_PROJECT, R.layout.itemview_home_project)
    }

    var collectListener = { position: Int -> }

    fun setCollectClickListener(listener: (position: Int) -> Unit) {
        collectListener = listener
    }

    override fun convert(holder: BaseDataBindingHolder<ViewDataBinding>, item: ArticleBean) {
        when (holder.itemViewType) {
            Constants.ITEM_ARTICLE -> {
                var viewBinding = holder.dataBinding as ItemviewHomeArticleBinding
                viewBinding.item = item
                viewBinding.ivCollect.setOnClickListener {
                    collectListener.invoke(holder.adapterPosition)
                }
                viewBinding.executePendingBindings()
            }
            Constants.ITEM_PROJECT -> {
                var viewBinding = holder.dataBinding as ItemviewHomeProjectBinding
                viewBinding.item = item
                viewBinding.ivCollect.setOnClickListener {
                    collectListener.invoke(holder.adapterPosition)
                }
                viewBinding.executePendingBindings()
            }
        }
    }
}